YAHOO.example.DDPlayer = function(id, sGroup, config) {
    YAHOO.example.DDPlayer.superclass.constructor.apply(this, arguments);
    this.initPlayer(id, sGroup, config);
};

YAHOO.extend(YAHOO.example.DDPlayer, YAHOO.util.DDProxy, {

    TYPE: "DDPlayer",

    initPlayer: function(id, sGroup, config) {
        if (!id) { 
            return; 
        }

        var el = this.getDragEl()
        YAHOO.util.Dom.setStyle(el, "borderColor", "transparent");
        YAHOO.util.Dom.setStyle(el, "opacity", 0.76);

        // specify that this is not currently a drop target
        this.isTarget = false;

        this.originalStyles = [];

        this.type = YAHOO.example.DDPlayer.TYPE;
        this.slot = null;

        this.startPos = YAHOO.util.Dom.getXY( this.getEl() );
        //YAHOO.log(id + " startpos: " + this.startPos, "info", "example");
    },

    startDrag: function(x, y) {
        //YAHOO.log(this.id + " startDrag", "info", "example");
        var Dom = YAHOO.util.Dom;
			
        var dragEl = this.getDragEl();
        var clickEl = this.getEl();
		//Dom.setStyle(clickEl, "opacity", 0.1);
		if (clickEl.className != 'selected') clickEl.className = 'selected';
		
		var item, selectedItems = Gridview.selectedItems;
		var i, length = selectedItems.length;
		var htmlArray = new Array();
		for (i=0; i<length; i++)
		{
			item = selectedItems[i];
			if (_viewType > 0)
				htmlArray.push('<img src="images/blank.gif" height="' + item.offsetHeight + '" width="' + item.offsetWidth + '" style="border:solid 2px grey; margin:3px;" />');
			else
				htmlArray.push('<img src="images/blank.gif" height="22" width="120" style="border:solid 2px grey; margin:3px;" />');
		}
        dragEl.innerHTML = _viewType > 0 ? htmlArray.join(' ') : htmlArray.join('<br />');
        //dragEl.className = 'selected';
        dragEl.style.height = 'auto';
        dragEl.style.width = 'auto';
        Dom.setStyle(dragEl, "opacity", 0.2);

        //Dom.setStyle(dragEl, "color",  Dom.getStyle(clickEl, "color"));
        //Dom.setStyle(dragEl, "backgroundColor", Dom.getStyle(clickEl, "backgroundColor"));

        //Dom.setStyle(clickEl, "opacity", 0.1);

        /*var targets = YAHOO.util.DDM.getRelated(this, true);
        YAHOO.log(targets.length + " targets", "info", "example");
        for (var i=0; i<targets.length; i++) {
            
            var targetEl = this.getTargetDomRef(targets[i]);

            if (!this.originalStyles[targetEl.id]) {
                this.originalStyles[targetEl.id] = targetEl.className;
            }

            targetEl.className = "target";
        }*/
    },

    getTargetDomRef: function(oDD) {
        if (oDD.player) {
            return oDD.player.getEl();
        } else {
            return oDD.getEl();
        }
    },

    endDrag: function(e) {
        // reset the linked element styles
        YAHOO.util.Dom.setStyle(this.getEl(), "opacity", 1);
        if (this.overEl) this.overEl.className = '';
		Gridview.node.className = 'selected';
        this.resetTargets();
    },

    resetTargets: function() {

        // reset the target styles
        /*var targets = YAHOO.util.DDM.getRelated(this, true);
        for (var i=0; i<targets.length; i++) {
            var targetEl = this.getTargetDomRef(targets[i]);
            var oldStyle = this.originalStyles[targetEl.id];
            if (oldStyle) {
                targetEl.className = oldStyle;
            }
        }*/
    },

    onDragDrop: function(e, id) {
        // get the drag and drop object that was targeted
        var oDD;
        
        if ("string" == typeof id) {
            oDD = YAHOO.util.DDM.getDDById(id);
        } else {
            oDD = YAHOO.util.DDM.getBestMatch(id);
        }
        Gridview.moveSelectedItemsToTarget(oDD.getEl(), e);
        
//		YAHOO.util.DDM.moveToEl(oDD.player.getEl(), el);

//        YAHOO.util.DDM.moveToEl(el, oDD.getEl());
//        this.resetTargets();

//        this.slot = oDD;
//        this.slot.player = this;
    },

    swap: function(el1, el2) {
        var Dom = YAHOO.util.Dom;
        var pos1 = Dom.getXY(el1);
        var pos2 = Dom.getXY(el2);
        Dom.setXY(el1, pos2);
        Dom.setXY(el2, pos1);
    },

    onDragOver: function(e, id) {
		var Dom = YAHOO.util.Dom;
		var srcEl = this.getEl();
        var destEl = Dom.get(id);
        if (this.overEl) this.overEl.className = '';

        // We are only concerned with list items, we ignore the dragover
        // notifications for the list.
        //if (destEl.nodeName.toLowerCase() == 'a' && $(destEl).ancestors().indexOf($('treeview')) != -1) {
            this.overEl = destEl;
            this.overEl.className = 'selected';
            
            YAHOO.util.DDM.refreshCache();
        //}
    },

    onDrag: function(e, id) {
    }
});

var slots = [], players = [];

